INBOUND EMAIL ACTION SCRIPTING
Requirement: Creating incidents for every single email attachment through inbound action.
Components Used:
- Inbound Action on Incident Table
- 'sys_email_attachment' Table
- 'sys_attachment' Table
Script for Inbound Email Action:
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
// Implement email action here
var emailSysId = sys_email.getUniqueValue(); // sys_id of email log record
var qq="email="+emailSysId; //query to fire on sys_email_attachment table
var i=0;
gs.log("Email sys_id is: " + emailSysId, "EMAILSCRIPT");
var gr = new GlideRecord('sys_email_attachment');
gr.addEncodedQuery(qq);
gr.orderByDesc('sys_created_on');
gr.query();
while(gr.next()){
var gr1=new GlideRecord("incident");
gr1.short_description="Attachment number"+i; //Hardcoded short description
var t=gr1.insert();
i++;
var attachment = new GlideRecord('sys_attachment');
attachment.get(gr.attachment);
attachment.table_name ="incident";
attachment.table_sys_id = t;
attachment.update();
}
})(current, event, email, logger, classifier);